package com.jingdong.controller;



import com.jingdong.pojo.GuanZhuDetail;
import com.jingdong.pojo.QianDaoDetail;
import com.jingdong.service.GuanZhuDetailCategoryService;
import com.jingdong.service.QianDaoDetailCategoryService;
import com.jingdong.utils.DateUtil;
import com.jingdong.utils.ResultVOUtil;
import com.jingdong.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author Zqm
 */
@RestController
@RequestMapping("/qiandao")
public class QianDaoDetailController {


    @Autowired
    private QianDaoDetailCategoryService qianDaoDetailCategoryService;



    @RequestMapping("/doQuery")
    public  ResultVO guanzhudetail(){
        try {
            Page<QianDaoDetail> all = qianDaoDetailCategoryService.findAll(1,10);
            ResultVO success = ResultVOUtil.succecss(all);
            return success;
        }catch (Exception e){
            return  null;
        }
    }

    //TODO 改成存储是短链接
    @RequestMapping("/add")
    public  ResultVO guanzhudetail(@RequestParam(value = "url", required = false, defaultValue = "-1") String url){
        QianDaoDetail qianDaoDetail=new QianDaoDetail();
        qianDaoDetail.setUrl(url);
        qianDaoDetail.setTimes(DateUtil.parseDateToStr(new Date(),"yyyy-MM-dd HH:mm:ss"));
        ResultVO resultVO=null;
        try {
             resultVO= qianDaoDetailCategoryService.save(qianDaoDetail);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            return resultVO;
        }

    }


}
